import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Calendar;

public class Driver
{

  private int driverId;
  private int holidays;
  private int startTime;
  private int test = 0;
  private int endTime;
  private int tHours;
  private Date date;

  private Driver(int driverId, Date date, int startTime, int endTime, int tHours)
  {
    this.driverId = driverId;
    this.date = date;
    this.startTime = startTime;
    this.endTime = endTime;
    this.tHours = tHours;
    test = 1;
  }

  private Driver(int driverId)
  {
    this.driverId = driverId;
    this.holidays = 25;
  }

  public static Driver createDriver(int driverId, Date date, 
                                    int startTime,int endTime, int tHours)
  {
    Driver driver = new Driver(driverId, date, startTime, endTime, tHours);
    return driver;
  }
  
  public static Driver createDriver(int driverId)
  {
    Driver driver = new Driver(driverId);
    return driver;
  }

  public int getDriverId()
  {
    return this.driverId;
  }

  public int getHolidays()
  {
    return this.holidays;
  }

  public String getName()
  {
    return DriverInfo.getName(this.driverId);
  }
  
  public int getStartTime()
  {
    return this.startTime;
  }
  
  public int getEndTime()
  {
    return this.endTime;
  }
  
  public boolean isAvailable()
  {
    return DriverInfo.isAvailable(this.driverId, date);
  }

  public int getHolidaysTaken()
  {
    return DriverInfo.getHolidaysTaken(this.driverId);
  }

  public int getHolidaysLeft()
  {
    return this.holidays - DriverInfo.getHolidaysTaken(this.driverId);
  }

  public HolidayRequest createHolidayRequest(String start, String end, int id)
  {
    Date startDay = null;
    Date endDay = null;
    try
    {
      DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
      Calendar c = Calendar.getInstance();
      startDay = df.parse(start);
      endDay = df.parse(end);
    }
    catch (ParseException e)
    {
      System.err.println("Caught IOException: " + e.getMessage());
    }
    HolidayRequest request = new HolidayRequest(startDay, endDay, id);

    return request;
  }
  
  public String toStringID()
  {
    return "" + this.driverId;
  }
  
  public String toStringStartTime()
  {
    return "" + this.startTime;
  }
  
  public String toStringEndTime()
  {
    return "" + this.endTime;
  }
  
  public double getTotalHours()
  {
    return this.tHours/60.0;
  }
  
  public String toStringDate()
  {
    return "" + this.date;
  }
  
  public int test()
  {
    return test;
  }
  
  
  
  
}